//
//  DetailsOfIncomeAndExpenditureViewModel.m
//  GLGW_Shoping
//
//  Created by whx on 2018/12/7.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "DetailsOfIncomeAndExpenditureViewModel.h"
#import "NoDataFootTableViewHeaderFooterView.h"
#import "WithDrawlRecordDetailTableViewCell.h"

@interface DetailsOfIncomeAndExpenditureViewModel()<UITableViewDelegate, UITableViewDataSource>
{
    UITableView *selfTableView;
    NSMutableArray *leftArr;
}

@end

@implementation DetailsOfIncomeAndExpenditureViewModel

- (instancetype)initWithViewToViewModel:(UITableView *)tableView theSuperView:(UIView *)superView
{
    if (self = [super initWithViewToViewModel:tableView theSuperView:superView]) {
        leftArr = [NSMutableArray arrayWithObjects:@[@"流水单号", @"金额", @"收支", @"方式", @"类型", @"时间"], nil];
        tableView.backgroundColor = [UIColor colorWithHexString:@"#F2F2F2"];
        tableView.delegate = self;
        tableView.dataSource = self;
        tableView.sectionFooterHeight = 0.0;
        tableView.sectionHeaderHeight = 0.0;
        [tableView registerClass:[NoDataFootTableViewHeaderFooterView class] forHeaderFooterViewReuseIdentifier:@"NoDataFootTableViewHeaderFooterView"];
        [superView addSubview:tableView];
        selfTableView = tableView;
    }
    return self;
}

- (void)setType:(DetailsOfIncomeAndExpenditureType)type
{
    _type = type;
    NSArray *diArr;
    if (type == DetailsOfIncomeAndExpenditureType_Order) { // 订单
        diArr = @[@"查看相关订单"];
    } else if (type == DetailsOfIncomeAndExpenditureType_LookingFor) {
        diArr = @[@"查看相关求购单"];
    } else if (type == DetailsOfIncomeAndExpenditureType_Offer) {
        diArr = @[@"查看相关报价"];
    }
    [leftArr addObject:diArr];
    [selfTableView reloadData];
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return kHeightProportion_In_iPhoneTriploid(10);
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    NoDataFootTableViewHeaderFooterView *footer = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"NoDataFootTableViewHeaderFooterView"];
    return footer;
}

#pragma mark - tableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return leftArr.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [leftArr[section] count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    WithDrawlRecordDetailTableViewCell *detailCell = [WithDrawlRecordDetailTableViewCell cellWithTableView:tableView];
    if (indexPath.section == 1) {
        detailCell.leftColorStr = @"#333333";
        detailCell.rightLab.hidden = YES;
        detailCell.showPush = YES;
    } else {
        detailCell.leftColorStr = @"#999999";
        detailCell.rightLab.hidden = NO;
        detailCell.showPush = NO;
    }
    if (indexPath.row == 1) {
        detailCell.rightLab.textColor = [UIColor colorWithHexString:@"#EC5353"];
    } else {
        detailCell.rightLab.textColor = kColor_Rule_Black;

    }
    detailCell.leftStr = leftArr[indexPath.section][indexPath.row];
    return detailCell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 1) {
        if (self.BlockSelet) {
            self.BlockSelet(indexPath);
        }
    }
}

@end
